<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
  >
    <template #searchPanel>
      <search-panel
        v-slot="{ form }"
        :addPer="'purchaseReturn:save'"
        :selectPer="'purchaseReturn:page'"
        addTitle="新增退货"
        @insert="add"
        @search="search"
        :showSearchButton="true"
        :showAddButton="true"
      >
        <Job-shop v-model="form.storeId" placeholder="所属门店" />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
        @row-dblclick="view"
      >
        <template #action="{ row }">
          <i
            class="el-icon-edit"
            title="编辑"
            style="cursor: pointer"
            v-permission="'purchaseReturn:update'"
            @click="handleDataUpdateEdit(row, '编辑')"
          ></i>
          <i
            class="el-icon-delete"
            title="删除"
            style="color: red; margin-left: 20px; cursor: pointer"
            v-permission="'purchaseReturn:del'"
            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>
    </template>
    <template #dialog>
      <dialog-view-detail :id="viewId" />
    </template>
  </base-layout>
</template>
<script>
import baseMixin from "@/mixins/base";
import {
  page,
  deleteById,
  getFindById,
} from "@/api/after-sale/purchaseManage/purchaseReturn";
import DialogViewDetail from "./view/index";
export default {
  components: {
    DialogViewDetail,
  },
  mixins: [
    baseMixin({
      idName: "id",
      findData: page,
      dataName: ["content", "totalRecords"],
      format(res) {
        return res.map((data) => {
          return data;
        });
      },
      findDataById: getFindById,
      deleteData: deleteById,
    }),
  ],
  data() {
    return {
      tableColumnAttributes: [
        { name: "退货门店", value: "storeName", type: "text" },
        { name: "退货编号", value: "returnCode", type: "text" },
        { name: "退货类型", value: "returnType", type: "text" },
        { name: "退货供应商", value: "supplierName", type: "text" },
        { name: "退货负责人", value: "userName", type: "text" },
        { name: "负责人联系方式", value: "phone", type: "text" },
        { name: "退货总金额", value: "amount", type: "text" },
        { name: "退货备注", value: "remark", type: "text" },
        { name: "状态", value: "status", type: "text" },
        { name: "退货时间", value: "createTime", type: "text" },
      ],
      viewId: null,
    };
  },
  methods: {
    add() {
      this.$router.push({ path: "/partsStock/purchaseManage/addPurchaseReturn" });
    },
    handleDataUpdateEdit(row, type) {
      this.$router.push({
        path: "/partsStock/purchaseManage/editPurchaseReturn",
        query: {
          id: row.id,
        },
      });
    },
    search(form) {
      this.searchOptions = form;
      this.currentPage = 1;
      this.setTableData();
    },
    view(row) {
      this.viewId = row.id;
      this.handleDataInsert("采购退货详情");
    },
  },
};
</script>
